package org.teststack.utils;

import java.sql.*;

public class DatabaseExample {
    public static void main(String[] args) {
        String url = ReadConf.readConf("jdbc-url");
        String username = ReadConf.readConf("username");
        String password = ReadConf.readConf("password");

        try (Connection conn = DriverManager.getConnection(url, username, password)) {
            String selectSql = "SELECT * FROM QCDZ_MC_SL_MCBYJL where entname = '发的嘎晒的建筑设计事务所（浙江）有限公司'";

            try (ResultSet res = execSelect(conn, selectSql)) {
                printNameId(res);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static ResultSet execSelect(Connection conn, String sql) throws SQLException {
        Statement statement = conn.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        return resultSet;
    }

    private static void printNameId(ResultSet resultSet) throws SQLException {
        // 遍历每一行
        while (resultSet.next()) {
            // 获取 name_id 列的值
            String nameId = resultSet.getString("name_id");
            // 打印 name_id 的值
            System.out.println("name_id: " + nameId);
        }
    }
    }

